<template>
  <view class="common-card scroll-x-box">
    <view class="title-box">
      <view class="sub-title">热门</view>
      <view class="title">推荐歌单</view>
    </view>
    <view class="m-content">
      <scroll-view :scroll-x="true" class="scroll-X">
        <view class="poster-list-item" v-for="(item, index) in topPlaylist" :key="item.id">
          <view class="image-box">
            <image
              border-radius="10"
              :src="item.coverImgUrl + '?param=270y270'"
              style="width: 102px; height: 102px"
            />
            <view class="dt-count">
              {{ item.playCount }}
            </view>
          </view>
          <view class="line-2" style="white-space: pre-wrap; word-wrap: break-word; -webkit-line-clamp: 2">{{
            item.name
          }}</view>
        </view>
      </scroll-view>
    </view>
  </view>
</template>
<script lang="ts">
import { defineComponent, ref, watch } from 'vue'

export default defineComponent({
  props: {
    topPlaylist: {
      type: Array,
      default: () => {
        return []
      },
    },
  },
  setup(props, { emit }) {
    let topPlaylist: any = ref(props.topPlaylist)
    watch(
      () => props.topPlaylist,
      (newVal) => {
        topPlaylist.value = newVal
      }
    )
    return { topPlaylist }
  },
})
</script>

<style lang="scss" scoped>
/* 横向滚动 */
.scroll-x-box {
}
.scroll-x-box .scroll-X {
  width: 100%;
  overflow: hidden;
  white-space: nowrap;
}
.scroll-x-box .scroll-X .poster-list-item {
  width: 200rpx;
  display: inline-block;
  margin-right: 30rpx;
}
.scroll-x-box .scroll-X .poster-list-item .image-box {
  position: relative;
  width: 104px;
  height: 104px;
  border-radius: 5px;
  overflow: hidden;
  opacity: 1;
  transition: opacity 0.5s ease-in-out 0s;
  background-color: transparent;
}
.scroll-x-box .scroll-X .poster-list-item .image-box .dt-count {
  position: absolute;
  top: 0;
  right: 0;
  color: #ffffff;
  background-color: rgba(0, 0, 0, 0.1);
  border-radius: 10rpx;
  padding: 0 5rpx;
  font-size: 26rpx;
}
.scroll-x-box .scroll-X .poster-list-item .song-name {
  height: auto;
  color: #333;
  margin-top: 8rpx;
  font-size: 26rpx;
  word-wrap: break-word;
  word-break: normal;
}
.line-2 {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  font-size: 12px;
}
.title{
      font-size: 16px;
    font-weight: bolder;
    margin-top: 1px;
}
</style>
